package com.jiangjiang.eshop.finance.controller;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.jiangjiang.eshop.finance.constant.PurchaseSettlementOrderApproveResult;
import com.jiangjiang.eshop.finance.constant.PurchaseSettlementOrderStatus;
import com.jiangjiang.eshop.finance.domain.PurchaseSettlementOrder;
import com.jiangjiang.eshop.finance.dto.ApproveParam;
import com.jiangjiang.eshop.finance.dto.PurchaseSettlementOrderDTO;
import com.jiangjiang.eshop.finance.dto.PurchaseSettlementOrderQuery;
import com.jiangjiang.eshop.finance.service.PurchaseSettlementOrderService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * @ClassName PurchaseSettlementOrderController
 * @Description TODO
 * @Author jhw
 * @Date 2021/9/16 0:05
 * @Version 1.0
 **/
@Slf4j
@RestController
@RequestMapping("/purchase/settlement/order")
public class PurchaseSettlementOrderController {
    @Autowired
    private PurchaseSettlementOrderService purchaseSettlementOrderService;


    /**
     * 采购结算单分页数据查询
     *
     * @param req 分页查询条件
     * @return 分页查询结果
     */
    @PostMapping("/queryForPage")
    public Page<PurchaseSettlementOrderDTO> queryForPage(@RequestBody PurchaseSettlementOrderQuery req) {
        try {
            return purchaseSettlementOrderService.queryForPage(req);
        } catch (Exception e) {
           log.warn("PurchaseSettlementOrderController queryForPage error",e);
        }
        return null;
    }


    /**
     * 根据id 查询采购结算单
     *
     * @param id 采购结算单id
     * @return 查询结果
     */
    @GetMapping("/getById/{id}")
    public PurchaseSettlementOrderDTO queryById(@PathVariable("id") Long id) {
        try {
            return purchaseSettlementOrderService.queryById(id);
        } catch (Exception e) {
            log.warn("PurchaseSettlementOrderController queryById error",e);
        }
        return null;
    }

    /**
     * 采购结算单编辑
     * @param order
     * @return
     */
    @PostMapping("/update")
    public Boolean updateSettlementOrder(@RequestBody PurchaseSettlementOrderDTO order) {
        try {
            return purchaseSettlementOrderService.updateSettlementOrder(order);
        } catch (Exception e) {
            log.warn("PurchaseSettlementOrderController updateSettlementOrder error",e);
        }
        return false;
    }

    /**
     * 采购结算单提交审核
     * @param id
     * @return
     */
    @GetMapping("/submitApprove/{id}")
    public Boolean submitApprove(@PathVariable("id") Long id){
        try {
            return purchaseSettlementOrderService.submitApprove(id);
        } catch (Exception e) {
            log.warn("PurchaseSettlementOrderController submitApprove error",e);
        }
        return false;
    }

    /**
     * 采购结算单审核
     * @param id
     * @return
     */
    @PostMapping("/approve")
    public Boolean approve(@RequestBody ApproveParam param){
        try {
            return purchaseSettlementOrderService.approve(param.getPurchaseSettlementOrderId(), param.getApprovedResult());
        } catch (Exception e) {
            log.warn("PurchaseSettlementOrderController approve error",e);
        }
        return false;
    }

}
